{% extends 'base_tabler.html' %} {% load static %} {% block content %}
<div class="container-xl">
  <div class="page-header d-print-none">
    <div class="row align-items-center">
      <div class="col">
        <h2 class="page-title">数据管理</h2>
      </div>
      <div class="col-auto ms-auto d-print-none">
        <a href="{% url 'admin_dashboard' %}" class="btn btn-secondary"> 返回仪表盘 </a>
      </div>
    </div>
  </div>

  <div class="card mt-3">
    <div class="card-header">
      <h3 class="card-title">上传的文件</h3>
    </div>
    <div class="table-responsive">
      <table class="table table-vcenter card-table">
        <thead>
          <tr>
            <th>文件名</th>
            <th>大小</th>
            <th>上传时间</th>
            <th>最后修改</th>
            <th class="w-1">操作</th>
          </tr>
        </thead>
        <tbody>
          {% if files %} {% for file in files %}
          <tr>
            <td>{{ file.name }}</td>
            <td>{{ file.size|filesizeformat }}</td>
            <td>{{ file.created|date:"Y-m-d H:i" }}</td>
            <td>{{ file.modified|date:"Y-m-d H:i" }}</td>
            <td>
              <div class="btn-group">
                <a href="/media/{{ file.name }}" class="btn btn-primary btn-sm" download> 下载 </a>
                <form method="post" style="display: inline">
                  {% csrf_token %}
                  <input type="hidden" name="file_name" value="{{ file.name }}" />
                  <button
                    type="submit"
                    name="action"
                    value="delete"
                    class="btn btn-danger btn-sm"
                    onclick="return confirm('确定要删除该文件吗？')"
                  >
                    删除
                  </button>
                </form>
              </div>
            </td>
          </tr>
          {% endfor %} {% else %}
          <tr>
            <td colspan="5" class="text-center">暂无上传的文件</td>
          </tr>
          {% endif %}
        </tbody>
      </table>
    </div>
  </div>

  <div class="card mt-3">
    <div class="card-header">
      <h3 class="card-title">上传新文件</h3>
    </div>
    <div class="card-body">
      <form method="post" enctype="multipart/form-data" action="{% url 'upload' %}">
        {% csrf_token %}
        <div class="mb-3">
          <div class="form-label">选择 Excel 文件</div>
          <input type="file" class="form-control" name="file" accept=".xlsx,.xls" />
        </div>
        <div class="mt-2">
          <button type="submit" class="btn btn-primary">上传文件</button>
        </div>
      </form>
    </div>
  </div>
</div>
{% endblock %}
